<?php 

class Login_Model extends CI_Model
{ 
    function loginUser($username,$password)
    {
        $this->load->library('encrypt');
        $this->db->select('U.USUA_ID AS id,USUA_NOMBRES AS names,USUA_APELLIDOS AS lastnames,FUNC_CONTRASENA AS password,FUNC_USUARIO AS user,CAR_NOMBRE AS chargue');
        $this->db->from('USUARIO AS U');
        $this->db->join('FUNCIONARIO AS F','F.USUA_ID=U.USUA_ID','INNER');
        $this->db->join('FUNCIONARIODESEMPENIACARGO AS FDC','FDC.USUA_ID=F.USUA_ID','INNER');
        $this->db->join('CARGO AS C','FDC.CAR_ID=C.CAR_ID','INNER');
        $query = $this->db->get();
        if($query->num_rows() > 0)
        {
            $result=$query->result();
            foreach ($result as $user) 
            {
                $password_decode=$this->encrypt->decode($user->password);
                if($password_decode==$password&&$username==$user->user)
                {
                    return $user;
                }
            }
            return FALSE;
        }
        else
        {
            return FALSE;
        }
    }
}

?>